<%@page import="bll.EnumName"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.*,util.*,dal.*,model.*, bll.*"%>
<%
// 	String objectType=MiscUtil.getStringUrlParam(request, "objectType");
// 	int objectId=MiscUtil.getIntUrlParam(request, "objectId");
	DocumentModel obj;
	Object temp = request.getAttribute("document");
	if (temp != null) {
		try {
			obj = (DocumentModel) temp;
		} catch (Exception ex) {
			obj = new DocumentModel();
		}
	} else {
		obj = new DocumentModel();
	}
	String objectType=obj.getObjectTypeToString();
	int objectId=obj.getObjectId();
	String type="";
	String name="";
	if(objectType.equals("project"))
	{
		type="Project";
		name=CacheUtil.getProjectName(objectId);
	}
	if(objectType.equals("phase"))
	{
		type="Phase";
		name=CacheUtil.getPhaseName(objectId);
	}
	if(objectType.equals("checklist_item"))
	{
		type="Checklist Item";
		name=CacheUtil.getChecklistItemName(objectId);
	}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit Document</title>
<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/inputForm.css" />
<link rel="stylesheet" href="css/listForm.css" />
<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
<link rel="stylesheet" href="css/hyjack.css" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<link rel="stylesheet" href="css/themes/ui-lightness/jquery.ui.all.css" />
<link rel="stylesheet" href="css/jquery-ui-timepicker.css" type="text/css" />
<link rel="stylesheet" href="css/jquery-datepicker.css" />
<link rel="stylesheet" href="css/jquery-dialog.css" />

<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.select.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.core.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.widget.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.timepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.js"></script>
<script language="javascript" type="text/javascript" src="js/ajaxQuickInsert.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.numeric.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.tools.min.js"></script>
<script language="javascript" type="text/javascript" src="js/common.js"></script>


<script language="javascript" type="text/javascript">
$(document).ready(pageLoaded);

function pageLoaded()
{
	turnOnNumbericInput();
	initTooltip();	
} 

var requiredInputs = [['document_name','document_name_required'],['document_type','document_type_required']];
var intInputs = [];
var doubleInputs = [];
var dateInputs = [];
var timeInputs = [];


function checkInputs() {
	var valid = true;

	if (checkRequiredInputs(requiredInputs) == false) {
		valid = false;
	}
	if (checkIntInputs(intInputs) == false) {
		valid = false;
	}
	if (checkDoubleInputs(doubleInputs) == false) {
		valid = false;
	}
	if (checkDateInputs(dateInputs) == false) {
		valid = false;
	}
	if (checkTimeInputs(timeInputs) == false) {
		valid = false;
	}
	

	// SPECIFIC VALIDATE CODE HERE		

	return valid;
}

	
</script>
</head>
<body>
	<div class="divContainer">
		<%@ include file="menu.jsp"%>
				<form id="inputForm" action="document?mode=update&objectType=<%=objectType %>&objectId=<%=objectId %>" method="post" onSubmit="return checkInputs()">
					<table class="tblInput">
						<tr><td colspan="3">
							<b><%=type %>: <span ><%=name%></span></b>
						</td></tr>
						<tr>
							<td class="inputHeader">EDIT DOCUMENT INFO</td>
						</tr>
						<tr>
					<td style="padding-left: 400px; padding-right: 400px;">
						<table cellspacing="0px">
						<tr>
							<td class="tdFieldName">Id</td>
							<td class="tdFieldInput">
								<input class="inputInt readonly" type="text" id="id" name="id" readonly="readonly" value="<%=obj.getId()%>" title="Id of this document. Note: Can not edit."/>
								<span class="textGuide"> (Can not edit)</span>
							</td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Document Name</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="document_name" name="document_name" maxlength="255" value="<%=obj.getDocumentNameToString() %>" title="Name of this document. Note: Required." onblur="validateRequiredInput('document_name');"/>
							</td>
							<td class="tdErrMsg">
								<span id="document_name_required" class="errMsg" style="display: none;" title="Document name is required">(!)</span> 
							</td>
							
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Document type</td>
							<td class="tdFieldInput">
								<select id="document_type" name="document_type" class="hyjack" title="Choose a type for the document.">
								<%=HtmlUtil.<DocumentTypeModel>genModelSelect(CacheUtil.getDocumentTypeList(), null,obj.getDocumentType()) %>
								</select>
							
							</td>
							<td class="tdErrMsg"></td>
						</tr>
						
						<tr class="trField">
							<td class="tdFieldName">Description</td>
							<td class="tdFieldInput">
								<textarea id="description" name="description" rows="5" class="inputTextarea" title="Description for new document."><%=obj.getDescriptionToString() %></textarea>
							</td>
							<td class="tdErrMsg">
							</td>
							
						</tr>
						
						<tr class="trField">
							<td class="tdFieldName">Remark</td>
							<td class="tdFieldInput"><textarea id="remark" name="remark" rows="5" class="inputTextarea" title="Remark of new document."><%=obj.getRemarkToString() %></textarea>
							</td>
							<td class="tdErrMsg"></td>
							
						</tr>
						
						<tr class="trField">
							<td class="tdFieldName">Tags</td>
							<td class="tdFieldInput"><textarea rows="5" class="inputTextarea" title="Tags."></textarea>
							</td>
							<td class="tdErrMsg"></td>
							
						</tr>
						
						<tr class="trInputBottom">
							<td colspan="3" class="tdSubmit" style="text-align: center;"><input class="btnSubmit" type="submit" value="Submit" title="Click to save above information."/></td>

						</tr>
					</table>
				</td>
			</tr>
		</table>
	</form>
	<%
	
		String urlDocumentList = "documentList.jsp?embedded=true&objectType="+objectType+"&objectId="+objectId;
	%>
		<jsp:include page='<%=urlDocumentList%>'></jsp:include>
	</div>
</body>
</html>